/*
 * Created on Feb 4, 2011 by Eng. Julian Rousselot
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package ar.com.visualAORE.util;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JEditorPane;
import javax.swing.JTextPane;
import javax.swing.Timer;
import javax.swing.text.DefaultHighlighter.DefaultHighlightPainter;

/**
 * @author julian
 *
 */
public class BlinkPainter extends DefaultHighlightPainter {
    Color blinkColor;
    Color activeColor;
    
    public BlinkPainter(Color c, int blinkRate, final JEditorPane aTextPane) {
        super(null);
        blinkColor=c;

        Timer t=new Timer(blinkRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                changeColor(aTextPane);
            }
        });
        t.start();
    }

    protected void changeColor(JEditorPane aTextPane) {
        if (activeColor==blinkColor) {
            activeColor=aTextPane.getBackground();
        }
        else {
            activeColor=blinkColor;
        }
        aTextPane.repaint();
    }

    public Color getColor() {
        return activeColor;
    }

}